package im.dhc.gitdiff.common;

import im.dhc.gitdiff.util.PathUtil;

import java.io.BufferedWriter;
import java.io.IOException;

/**
 * @author songhaichao
 * @create 2020-06-09-11:23
 **/
public class RenameDiffHandler extends AbstractDiffHandler{

    public RenameDiffHandler(String oldPath, String newPath, BufferedWriter backupbw, BufferedWriter updatebw, BufferedWriter recoverbw) throws Exception {
        super(oldPath,newPath,backupbw,updatebw,recoverbw);
    }

    public void backupHandle() throws IOException {
        backupbw.write(backUp());
        backupbw.newLine();
    }

    public void updateHandle() throws IOException {
        if(!PathUtil.isJarFile(this.newPath)) {
            updatebw.write(delete(this.oldPath));
            updatebw.newLine();
        }
        updatebw.write(update());
        updatebw.newLine();
    }

    public void recoverHandle() throws IOException {
        if(!PathUtil.isJarFile(this.newPath)) {
            recoverbw.write(delete(this.newPath));
            recoverbw.newLine();
        }
        recoverbw.write(recover());
        recoverbw.newLine();
    }

    public void copyFileHandle() throws IOException {
        copyFile();
    }
}
